// 导出一个函数，用于将秒数转换为时分秒格式
export function convertTime(seconds: number | string) {
  // 如果seconds是字符串类型，则将其转换为数字类型
  if (typeof seconds === "string") {
    seconds = parseInt(seconds);
  }
  // 如果seconds不是数字类型或者小于0，则返回"00:00:00"
  if (isNaN(seconds) || seconds < 0) return "00:00:00";

  // 将秒数转换为分钟数
  let minutes = seconds / 60;
  // 将秒数取余，得到剩余的秒数
  let hours = seconds % 60;
  // 如果分钟数大于等于60，则将分钟数转换为小时数，并将分钟数取余
  if (minutes >= 60) {
    hours = minutes / 60;
    minutes = minutes % 60;
  }
  // 返回格式化后的时分秒字符串
  return `${Math.floor(hours).toString().padStart(2, "0")}:${Math.floor(minutes)
    .toString()
    .padStart(2, "0")}:${Math.floor(seconds % 60)
    .toString()
    .padStart(2, "0")}`;
}

export function isLeapYear(year: number) {
  return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
}

export function getWeekDay(date: Date) {
  const days = ["日", "一", "二", "三", "四", "五", "六"];
  return days[date.getDay()];
}

export function getMonthDays(year: number, month: number) {
  const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  if (month === 2 && isLeapYear(year)) {
    return 29;
  }
  return daysInMonth[month];
}

export function zero(str: string) {
  const n = parseInt(str);
  return n < 10 ? `0${n}` : n.toString();
}
